// Learn cc.Class:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const GameDataManger = require("../GameDataManger");

cc.Class({
    extends: cc.Component,

    properties: {
        coinLab:{    
            default:null,
            type:cc.Label
        },

        emojSp:{    
            default:null,
            type:cc.Sprite
        },

        emojLab:{    
            default:null,
            type:cc.Label
        },
        id:0,
    },
    onLoad(){
        //cc.systemEvent.on('refresGame', this.refresh, this);
    },

    onEnable(){
    },

    setData(type, data){
        if (type == 1){
            this.id = data;
            let url = 'imags/emoji/emo' + data
            GameDataManger.loadIamge(this.emojSp, url);
        }else{
            this.id = data.id;
            this.emojLab.string = data.des;
        }
        
    },

    btnClick(){
        //发送表情
        cc.systemEvent.emit('closeChatNode');
        if (GameDataManger.gold < 10){
            cc.systemEvent.emit('showTip', "金币不足");
            return;
        }
        GameDataManger.gold-=10;
        cc.systemEvent.emit('saveUserData');
        cc.systemEvent.emit('sendMessage', 1022,[this.id]);
    },

    onDisable(){
    },

    // update (dt) {},
});
